package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TicketTemplate;
import com.ruoyi.system.service.ITicketTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收据模板信息Controller
 *
 * @author ruoyi
 * @date 2024-07-15
 */
@RestController
@RequestMapping("/system/template")
public class TicketTemplateController extends BaseController
{
    @Autowired
    private ITicketTemplateService ticketTemplateService;

    /**
     * 查询收据模板信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(TicketTemplate ticketTemplate)
    {
        startPage();
        List<TicketTemplate> list = ticketTemplateService.selectTicketTemplateList(ticketTemplate);
        return getDataTable(list);
    }

    /**
     * 导出收据模板信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:export')")
    @Log(title = "收据模板信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TicketTemplate ticketTemplate)
    {
        List<TicketTemplate> list = ticketTemplateService.selectTicketTemplateList(ticketTemplate);
        ExcelUtil<TicketTemplate> util = new ExcelUtil<TicketTemplate>(TicketTemplate.class);
        util.exportExcel(response, list, "收据模板信息数据");
    }

    /**
     * 获取收据模板信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:template:query')")
    @GetMapping(value = "/{templateNo}")
    public AjaxResult getInfo(@PathVariable("templateNo") String templateNo)
    {
        return success(ticketTemplateService.selectTicketTemplateByTemplateNo(templateNo));
    }

    /**
     * 新增收据模板信息
     */
    @PreAuthorize("@ss.hasPermi('system:template:add')")
    @Log(title = "收据模板信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TicketTemplate ticketTemplate)
    {
        ticketTemplate.setCreateBy(getUsername());
        return toAjax(ticketTemplateService.insertTicketTemplate(ticketTemplate));
    }

    /**
     * 修改收据模板信息
     */
    @PreAuthorize("@ss.hasPermi('system:template:edit')")
    @Log(title = "收据模板信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TicketTemplate ticketTemplate)
    {
        ticketTemplate.setUpdateBy(getUsername());
        return toAjax(ticketTemplateService.updateTicketTemplate(ticketTemplate));
    }

    /**
     * 删除收据模板信息
     */
    @PreAuthorize("@ss.hasPermi('system:template:remove')")
    @Log(title = "收据模板信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{templateNos}")
    public AjaxResult remove(@PathVariable String[] templateNos)
    {
        return toAjax(ticketTemplateService.deleteTicketTemplateByTemplateNos(templateNos));
    }
}
